﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using DAO;
using System.Data;

namespace APA_DAO
{
    public class PhongDao
    {
        public PhongDao()
        {
            new SqlHelper();
        }
        //public bool insertPhong(int maCanHo, int soPhong, float donGia, float dienTich, int tinhTrang, string ghiChu)
        public bool insertPhong(string soPhong, string donGia, string dienTich,  string ghiChu)
        {
            return SqlHelper.ExecuteNonQuery("SP_INSERT_PHONG", CommandType.StoredProcedure,
                "@SO_PHONG", soPhong,
                "@DON_GIA", float.Parse(donGia.Replace(",","")),
                "@DIEN_TICH", float.Parse(dienTich.Replace(",", "")),
                "@GHI_CHU", ghiChu,
                "@USER_ID", LoginDao.userID);
        }

        public bool upadtePhong(string soPhong, string donGia, string dienTich, string ghiChu, int id)
        {
            return SqlHelper.ExecuteNonQuery("SP_UPDATE_PHONG", CommandType.StoredProcedure,
                "@SO_PHONG", soPhong,
                "@DON_GIA", float.Parse(donGia.Replace(",", "")),
                "@DIEN_TICH", float.Parse(dienTich.Replace(",", "")),
                "@GHI_CHU", ghiChu,
                "@USER_ID", LoginDao.userID,
                "@ID", id);
        }

        public bool deletePhong(int id)
        {
            return SqlHelper.ExecuteNonQuery("SP_DELETE_PHONG", CommandType.StoredProcedure,
                "@ID", id);        
        }

        public DataTable getPhongs(string soPhong, int status)
        {
            return SqlHelper.ExecuteDataTable("SP_GET_PHONG", CommandType.StoredProcedure,
                "@SO_PHONG", soPhong,
                "@TINH_TRANG", status);
        }

        public DataTable getPhongWithThuePhong()
        {
            return SqlHelper.ExecuteDataTable("SP_GET_PHONG_WITH_THUE_PHONG", CommandType.StoredProcedure);
        }
    }
}
